<template>
  <div>
    <div class="main-div">
      <keep-alive>
        <router-view></router-view>
      </keep-alive>
      <van-tabbar v-model="active" @change="changeTabbar(active)">
        <van-tabbar-item icon="shop">首页</van-tabbar-item>
        <van-tabbar-item icon="shop">分类</van-tabbar-item>
        <van-tabbar-item icon="cart">购物车</van-tabbar-item>
      </van-tabbar>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        active: 0,
        nowPath:'',//当前路径
      }
    },
    created(){
      this.changeTabBarActive()
    },
    updated(){
      this.changeTabBarActive()
    },
    methods:{
      changeTabBarActive(){
        this.nowPath = this.$route.path
        if(this.nowPath == '/cart'){
          this.active=2
        }
      },
      changeTabbar(i){
        switch(i){
          case 0:
            this.$router.push({name:'ShoppingMall'});break;
          case 1:
            this.$router.push({name:'CategoryList'});break;
          case 2:
            this.$router.push({name:'Cart'});break;

        }
      }
    },
  }
</script>

<style scoped>

</style>